using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.UserDomain;
using ShivamEMR.Model.DataInterfaces.UsersDataInterf;
using ShivamEMR.Model;
//using ShivamEMR.Web.Areas.User.Models;

namespace ShivamEMR.Web.Areas.User.Controllers
{   
    public class AccessPermissionController : Controller
    {
		private readonly IAccessPermissionRepository accesspermissionRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public AccessPermissionController() 
        {
            accesspermissionRepository = Registry.RepositoryFactory.GetAccessPermissionRepository();
        }

        public AccessPermissionController(IAccessPermissionRepository accesspermissionRepository)
        {
			this.accesspermissionRepository = accesspermissionRepository;
        }

        //
        // GET: /AccessPermission/

        public ViewResult Index()
        {
            //return View(accesspermissionRepository.AllIncluding(accesspermission => accesspermission.UserRights));
            return View(accesspermissionRepository.All);
        }

        //
        // GET: /AccessPermission/Details/5

        public ViewResult Details(int id)
        {
            return View(accesspermissionRepository.Find(id));
        }

        //
        // GET: /AccessPermission/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /AccessPermission/Create

        [HttpPost]
        public ActionResult Create(AccessPermission accesspermission)
        {
            if (ModelState.IsValid) {
               // accesspermissionRepository.InsertOrUpdate(accesspermission);
                accesspermissionRepository.Create(accesspermission);
                accesspermissionRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /AccessPermission/Edit/5
 
        public ActionResult Edit(int id)
        {
             return View(accesspermissionRepository.Find(id));
        }

        //
        // POST: /AccessPermission/Edit/5

        [HttpPost]
        public ActionResult Edit(AccessPermission accesspermission)
        {
            if (ModelState.IsValid) {
               // accesspermissionRepository.InsertOrUpdate(accesspermission);
                accesspermissionRepository.Update(accesspermission);
                accesspermissionRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /AccessPermission/Delete/5
 
        public ActionResult Delete(int id)
        {
            return View(accesspermissionRepository.Find(id));
        }

        //
        // POST: /AccessPermission/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
           // accesspermissionRepository.Delete(id);
            var ap = accesspermissionRepository.Find(id);
            accesspermissionRepository.Delete(ap);
            accesspermissionRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

